#ifndef SPHERE_H_
#define SPHERE_H_

#include "Object.h"
#include "Point.h"
#include "Vector.h"
#include <math.h>

namespace Geometry
{
	class Sphere : public Object
	{
		float m_radius;
		Point  m_center;

	public:
		Sphere():Object(),m_radius(0.0),m_center(){}
		Sphere( Point _c, float _r ):Object(), m_radius(_r), m_center(_c){}
		Sphere( Point _c, float _r, Properties::Color _color, Properties::Lighting _lighting ):Object(_color, _lighting), m_radius(_r), m_center(_c){}

		inline float r() const { return m_radius; };
		inline Point  c() const { return m_center; };

		virtual bool intersect(const Ray& _r, Point& _p, float& _t);
		inline virtual Ray getReflectedRay( const Ray& _incoming, const Point& _p );
		inline virtual Vector getNormal( const Point& _p );
		
	};

	inline Ray Sphere::getReflectedRay( const Ray& _incoming, const Point& _p )
	{
		Vector& V = _incoming.q();
		Vector& N = getNormal( _p );
		Vector& R = ( 2 * ( V * N ) * N ) - V;

		return Ray( _p , R );
	}

	inline Vector Sphere::getNormal( const Point& _p )
	{
		return Vector( 2 * ( _p.x() - c().x() ) , 2 * ( _p.y() - c().y() ) , 2 * ( _p.z() - c().z() ) ).unit();
	}
}

#endif